# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：      nacos
   Description:
   Author:          Lijiamin
   date：           2023/4/14 10:41
-------------------------------------------------
   Change Activity:
                    2023/4/14 10:41
-------------------------------------------------
"""
import logging
import nacos

from app.config import server_config

logger = logging.getLogger('nacos')
nacos_info = server_config.get('nacos')


def nacos_init():
    if not server_config.get('local_dev'):
        client = nacos.NacosClient(server_addresses=f"{nacos_info.get('nacos_url')}:{nacos_info.get('nacos_port')}", username="nacos", password=nacos_info.get('nacos_password'), log_level="INFO")
        status = client.add_naming_instance(service_name=nacos_info.get('service_name'), ip=nacos_info.get('backend_ip'), port=nacos_info.get('backend_port'), group_name="default", heartbeat_interval=5)
        if status:
            logger.info("nacos注册成功")


